﻿package org.openChart.display 
{
	import org.openChart.meta.BaseObject;
	
	/**
	 * A color label contains tow parts. The first one is a colored area and the second is a text label.
	 * 
	 * @author Chongyuan
	 */
	public class DisplayColorLabel extends DisplayBaseObject
	{
		// The shape type of colored area.
		private var shape_:String = SQUARE;
		// The text label.
		private var label_:DisplayTextLabel;
		// The size of colored area.
		private var size_:uint = 16;
		// The width of color label.
		private var width_:uint;
		// The height of color label.
		private var height_:uint;
		// The max width of color label.
		private var maxWidth_:Number = Number.MAX_VALUE;
		// The max height of color label.
		private var maxHeight_:Number = Number.MAX_VALUE;
		
		public static var DOT:String = "dot";
		public static var LINE:String = "line";
		public static var SQUARE:String = "square";
		
		public function DisplayColorLabel(object:BaseObject) 
		{
			super(null);
		}
		
		public override function initialize():void
		{
			initSize();
		}
		
		/**
		 * Calculate the size of color label.
		 */
		public function initSize():void
		{
			if (label_)
			{
				label_.maxHeight = maxHeight_;
				label_.maxWidth = maxWidth_ - size_;
				label_.initSize();
				this.width_ = label_.width + size_;
				this.height_ = Math.max(label_.height, size_);
			}
			else
			{
				this.width_ = this.height_ = size_;
			}
		}
		
		public function set shape(shape_:String):void
		{
			this.shape_ = shape_;
		}
		
		public function get shape():String
		{
			return this.shape_;
		}
		
		public function get size():uint
		{
			return size_;
		}
		
		public function set size(size_:uint):void
		{
			this.size_ = size_;
		}
		
		public function set label(label_:DisplayTextLabel):void
		{
			this.label_ = label_;
		}
		
		public function get label():DisplayTextLabel
		{
			return this.label_;
		}
		
		// read-only properties.
		public function get width():Number
		{
			return width_;
		}
		
		public function get height():Number
		{
			return height_;
		}
		
		// write-only properties.
		public function set maxHeight(maxHeight_:Number):void
		{
			this.maxHeight_ = maxHeight_;
		}
		
		public function set maxWidth(maxWidth_:Number):void
		{
			this.maxWidth_ = maxWidth_;
		}
		
		public function toString():String
		{
			var str:String = "\nObject:DisplayColorLabel ";
			str += "[chape = " + shape + "]";
			str += "[size = " + size + "]";
			str += "[width = " + width + "]";
			str += "[height = " + height + "]";
			str += "[position: x = " + position.x + ", y = " + position.y + "]";
			str += label;
			return str;
		}
	}
	
}